home *** CD-ROM | disk | FTP | other *** search
- package com.extensibility.app;
-
- import com.extensibility.plugin.PluginRegistry;
- import com.extensibility.plugin.api.LoginPanel;
- import com.extensibility.plugin.api.ResLocationContext;
- import com.extensibility.plugin.api.ResLocationPlugin;
- import com.extensibility.plugin.api.ResLocationPluginPanel;
- import com.extensibility.plugin.api.TreeBrowseContext;
- import com.extensibility.plugin.api.TreeBrowseListener;
- import com.extensibility.plugin.api.TreeBrowseModel;
- import com.extensibility.plugin.api.URIScheme;
- import com.extensibility.rock.QuietBtn;
- import com.extensibility.rock.RAction;
- import com.extensibility.rock.RDialog;
- import com.extensibility.util.ArrayHelp;
- import com.extensibility.xml.URI;
- import com.extensibility.xml.URISchemeRegistry;
- import java.awt.BorderLayout;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dialog;
- import java.awt.Dimension;
- import java.awt.Frame;
- import java.awt.Window;
- import java.io.File;
- import java.util.Enumeration;
- import java.util.Vector;
- import javax.swing.Box;
- import javax.swing.Icon;
- import javax.swing.JButton;
- import javax.swing.JDialog;
- import javax.swing.JTabbedPane;
- import javax.swing.KeyStroke;
- import javax.swing.border.EmptyBorder;
- import javax.swing.event.ChangeEvent;
- import javax.swing.event.ChangeListener;
-
- public class SaveURIDialog extends RDialog implements ResLocationContext, ChangeListener {
- protected static final KeyStroke ENTER_KEY = KeyStroke.getKeyStroke(10, 0);
- protected static final KeyStroke ESCAPE_KEY = KeyStroke.getKeyStroke(27, 0);
- Frame myParent = null;
- JTabbedPane tabs;
- URI baseURI;
- URI uri;
- protected boolean bSaving = true;
- protected boolean prepared = false;
- String okID = null;
- String cancelID = null;
- JButton okButton = null;
- JButton cancelButton = null;
- String title = null;
- String suffix;
- RAction okAction = new 4(this);
- RAction cancelAction = new 5(this);
- private static final int VERSION_NUMBER = 1;
-
- public void stateChanged(ChangeEvent var1) {
- Component var2 = this.tabs.getSelectedComponent();
- ResLocationPluginPanel var3 = (ResLocationPluginPanel)var2;
- var3.panelShown();
- }
-
- public URI getURI() {
- return this.uri;
- }
-
- public SaveURIDialog(Frame var1, URI var2) {
- super(var1, true);
- if (var2 == null) {
- this.baseURI = new URI();
- } else {
- this.baseURI = var2;
- }
-
- this.myParent = var1;
- }
-
- public SaveURIDialog(Frame var1, URI var2, String var3) {
- super(var1, true);
- this.title = var3;
- if (var2 == null) {
- this.baseURI = new URI();
- } else {
- this.baseURI = var2;
- }
-
- this.myParent = var1;
- }
-
- public URI getBaseURI() {
- return this.baseURI;
- }
-
- public void show() {
- this.ensurePrepared();
- super.show();
- }
-
- public void ensurePrepared() {
- if (!this.prepared) {
- this.prepared = true;
- this.prepare();
- }
-
- }
-
- protected void prepare() {
- this.prepared = true;
- if (this.title == null) {
- this.title = UI.getString("dialog.save.uri.title");
- }
-
- ((Dialog)this).setTitle(this.title);
- ((JDialog)this).getContentPane().setLayout(new BorderLayout());
- Box var1 = Box.createHorizontalBox();
- this.fillButtonBox(var1);
- Box var2 = Box.createVerticalBox();
- ((Container)var2).add(var1);
- ((Container)var2).add(Box.createVerticalStrut(8));
- this.tabs = new JTabbedPane();
- this.tabs.setBorder(new EmptyBorder(8, 8, 8, 8));
- if (this.baseURI == null) {
- this.suffix = null;
- } else {
- this.suffix = this.baseURI.getShortName();
- int var3 = this.suffix.lastIndexOf(".");
- if (var3 >= 0) {
- this.suffix = this.suffix.substring(var3 + 1);
- } else {
- this.suffix = null;
- }
- }
-
- Vector var10 = new Vector();
- PluginRegistry var4 = PluginRegistry.getRegistry();
- int var5 = var4.getPluginApiCount("ResourceLocation01");
-
- for(int var6 = 0; var6 < var5; ++var6) {
- ResLocationPlugin var7 = (ResLocationPlugin)var4.getNthPlugin("ResourceLocation01", var6);
- var7.initialize(this);
- if (this.pluginIsAppropriate(var7)) {
- var10.addElement(var7);
- }
- }
-
- ArrayHelp.sort(0, var10.size(), new 6(var10, (SaveURIDialog)null, var10));
- boolean var11 = true;
- Enumeration var8 = var10.elements();
-
- while(var8.hasMoreElements()) {
- ResLocationPlugin var9 = (ResLocationPlugin)var8.nextElement();
- this.tabs.addTab(var9.getName(), (Icon)null, this.getPluginPanel(var9), (String)null);
- if (var11) {
- this.tabs.setSelectedIndex(0);
- var11 = false;
- }
- }
-
- this.tabs.getModel().addChangeListener(this);
- ((JDialog)this).getContentPane().add(this.tabs, "Center");
- ((JDialog)this).getContentPane().add(var2, "South");
- ((JDialog)this).getRootPane().registerKeyboardAction(this.cancelAction, "", ESCAPE_KEY, 2);
- ((JDialog)this).getRootPane().registerKeyboardAction(this.okAction, "", ENTER_KEY, 2);
- this.stateChanged((ChangeEvent)null);
- ((Window)this).pack();
- ((Component)this).setLocation(100, 100);
- Dimension var12 = ((Component)this).getSize();
- ((Component)this).setSize(new Dimension(Math.max(var12.width, 500), var12.height));
- }
-
- protected void fillButtonBox(Box var1) {
- ((Container)var1).add(Box.createHorizontalGlue());
- String var2 = this.cancelID != null ? this.cancelID : "dialog.cancel";
- this.cancelButton = new JButton(UI.getString(var2));
- this.cancelButton.addActionListener(this.cancelAction);
- this.cancelButton.setMnemonic(UI.getMnemonic("dialog.cancel"));
- ((Container)var1).add(this.cancelButton);
- ((Container)var1).add(Box.createHorizontalStrut(8));
- var2 = this.okID != null ? this.okID : (this.bSaving ? "dialog.save" : "dialog.open");
- this.okButton = new JButton(UI.getString(var2));
- this.okButton.setMnemonic(UI.getMnemonic(var2));
- this.okButton.addActionListener(this.okAction);
- ((Container)var1).add(this.okButton);
- ((Container)var1).add(Box.createHorizontalStrut(8));
- }
-
- protected boolean pluginIsAppropriate(ResLocationPlugin var1) {
- return var1.canSave(this.suffix);
- }
-
- protected ResLocationPluginPanel getPluginPanel(ResLocationPlugin var1) {
- return var1.getSavePanel(this);
- }
-
- public int getVersion() {
- return 1;
- }
-
- public boolean hasCapability(String var1) {
- return false;
- }
-
- public void setOKEnabled(boolean var1) {
- this.ensurePrepared();
- this.okButton.setEnabled(var1);
- }
-
- public void setOKID(String var1) {
- this.okID = var1;
- }
-
- public void setCancelID(String var1) {
- this.cancelID = var1;
- }
-
- public URIScheme confirmInput() {
- Component var1 = this.tabs.getSelectedComponent();
- ResLocationPluginPanel var2 = (ResLocationPluginPanel)var1;
- URISchemeRegistry var3 = URI.getRegistry();
- return var2.getValidSchemeResult(var3);
- }
-
- public TreeBrowseContext createBrowsing(TreeBrowseModel var1, TreeBrowseListener var2) {
- return new BrowseHelper(var1, var2);
- }
-
- public JButton createQuietButton(String var1, Icon var2) {
- return new QuietBtn(var1, var2, (RAction)null);
- }
-
- public LoginPanel getLoginPanel(String[] var1, String var2, String var3, String var4) {
- return new LoginPanelImpl(var1, var2, var3, var4);
- }
-
- public void okSave(URIScheme var1) {
- this.uri = new URI(var1);
- ((Window)this).dispose();
- }
-
- public void okOpen(URIScheme var1) {
- }
-
- public void cancel() {
- this.uri = null;
- ((Window)this).dispose();
- }
-
- public void setDefault(String var1) {
- this.ensurePrepared();
-
- for(int var2 = 0; var2 < this.tabs.getTabCount(); ++var2) {
- Component var3 = this.tabs.getComponentAt(var2);
- if (var3 instanceof ResLocationPluginPanel) {
- ((ResLocationPluginPanel)var3).setDefault(var1);
- }
- }
-
- }
-
- public void setPrompt(String var1) {
- this.ensurePrepared();
-
- for(int var2 = 0; var2 < this.tabs.getTabCount(); ++var2) {
- Component var3 = this.tabs.getComponentAt(var2);
- if (var3 instanceof ResLocationPluginPanel) {
- ((ResLocationPluginPanel)var3).setPrompt(var1);
- }
- }
-
- }
-
- public File askFile(String var1, String[] var2) {
- ((Component)this).setVisible(false);
- return DialogFactory.askFile(this.myParent, var1, var2);
- }
-
- public URIScheme getBaseLocation() {
- return this.baseURI.getSchemeObject();
- }
-
- public URIScheme createResLocation(URIScheme var1, String var2) {
- URI var3 = var1 != null && var1.hasPersistence() ? new URI(var1) : null;
- return (new URI(var3, var2)).getSchemeObject();
- }
-
- public URIScheme createResLocation(File var1) {
- URI var2 = new URI(var1);
- return var2.getSchemeObject();
- }
- }
-